home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !tex / TeXsource / beebe / h / signex < prev    next >
Encoding:
Text File  |  1990-05-18  |  1.8 KB  |  62 lines

  1. /* -*-C-*- signex.h */
  2. /*-->signex*/
  3. /**********************************************************************/
  4. /******************************* signex *******************************/
  5. /**********************************************************************/
  6.  
  7. #ifdef __STDC__
  8. INT32
  9. signex(register FILE *fp, register BYTE n)
  10. #else
  11. INT32
  12. signex(fp, n)     /* return n byte quantity from file fd */
  13. register FILE *fp;    /* file pointer     */
  14. register BYTE n;      /* number of bytes */
  15. #endif
  16. {
  17.     register BYTE n1; /* number of bytes      */
  18.     register INT32 number; /* number being constructed */
  19.  
  20.     number = (INT32)getc(fp);/* get first (high-order) byte */
  21.  
  22. #if    PCC_20
  23.     if (number > 127) /* sign bit is set, pad top of word with sign bit */
  24.     number |= 0xfffffff00;
  25.               /* this constant could be written for any */
  26.               /* 2's-complement machine as -1 & ~0xff, but */
  27.               /* PCC-20 does not collapse constant expressions */
  28.               /* at compile time, sigh... */
  29. #endif /* PCC_20 */
  30.  
  31. #if    (OS_ATARI | OS_UNIX)    /* 4.1BSD C compiler uses logical shift too */
  32.     if (number > 127) /* sign bit is set, pad top of word with sign bit */
  33.     number |= 0xffffff00;
  34. #endif /* OS_UNIX */
  35.  
  36.     n1 = n--;
  37.     while (n--)
  38.     {
  39.     number <<= 8;
  40.     number |= (INT32)getc(fp);
  41.     }
  42.  
  43. #if    (OS_ATARI | PCC_20 | OS_UNIX)
  44. #else /* NOT (OS_ATARI | PCC_20 | OS_UNIX) */
  45.  
  46.     /* NOTE: This code assumes that the right-shift is an arithmetic, rather
  47.     than logical, shift which will propagate the sign bit right.   According
  48.     to Kernighan and Ritchie, this is compiler dependent! */
  49.  
  50.     number<<=HOST_WORD_SIZE-8*n1;
  51.  
  52. #if    ARITHRSHIFT
  53.     number>>=HOST_WORD_SIZE-8*n1;  /* sign extend */
  54. #else /* NOT ARITHRSHIFT */
  55.     (void)fatal("signex():  no code implemented for logical right shift");
  56. #endif /* ARITHRSHIFT */
  57.  
  58. #endif /* (OS_ATARI | PCC_20 | OS_UNIX) */
  59.  
  60.     return((INT32)number);
  61. }
  62.